#include <gdk/gdkkeysyms.h>
#include <string.h>
#include "sms.h"

#define TEST_LAYOUT_NAME "layout-test"


typedef struct _Test_Layout
{
	GooCanvasItem *bg;
	GtkAdjustment *vadjustment;
}Test_Layout;


static gboolean test_layout_init(Layout *layout, gpointer data)
{
	printf("call %s\n",__FUNCTION__);

	GtkWidget *scrolled_win, *canvas;
	GooCanvasItem *scrolled, *root, *group, *bg, *text;
	GdkPixbuf*  pixbuf;

	Test_Layout *test_layout = (Test_Layout *)g_malloc0(sizeof(Test_Layout)+1);
	layout->private=(void *)test_layout;

	layout->cavas = goo_canvas_group_new(layout->parent, NULL);
	pixbuf=sms_load_pic("/usr/share/sms/default/layout/layout-setting/background1.png", 800, 480);


	scrolled_win = gtk_scrolled_window_new (NULL, NULL);
	//gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
	            GTK_SHADOW_IN);
	gtk_widget_show (scrolled_win);
	test_layout->vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_win));
	g_object_set(G_OBJECT(test_layout->vadjustment), "upper", 2000.0, NULL);


	scrolled = goo_canvas_widget_new(layout->cavas, scrolled_win, 0, 0, -1, -1, NULL);

    canvas = goo_canvas_new ();
    g_object_set (G_OBJECT (canvas),
              "automatic-bounds", TRUE,
              "bounds-from-origin", FALSE,
              "bounds-padding", 4.0,
              "background-color-rgb", 0xbdebf8,
              "has-tooltip", TRUE, NULL);
	gtk_widget_set_size_request (canvas, 400, 100);
	//goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 1000);
	gtk_widget_show (canvas);
	root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
	gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);
	//gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scrolled_win), canvas);
	printf("%s\n",__FUNCTION__);
	//group = goo_canvas_group_new(root, "x", 500, "y", 0, "width", 400, "height", 1000, NULL);
	/*bg = goo_canvas_image_new(group, pixbuf, 0, 0, NULL);
	goo_canvas_item_set_simple_transform(bg ,500 , 0 ,1 ,0);*/

	text = goo_canvas_text_new(root, "jhflakjsdhflkjashfl绿卡所觉得恢复拉开精华方腊快速解放\nlakjdfhlkja就阿可挥发卢克俭好嘞恐惧没那么发",//"a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n",
			     100, 0, 300, GTK_ANCHOR_NW,
			     "fill-color", 0,
	    //text = goo_canvas_text_new(root, "hello world", 0, 0, 200, GTK_ANCHOR_CENTER,
	            "font", "Sans 20",
	            "alignment", PANGO_ALIGN_CENTER,
	            "stroke-color", "black",
	            NULL);
	//goo_canvas_item_set_simple_transform(text, 500, 0, 1, 0);
	//goo_canvas_item_translate (text, 400, 0);


	return TRUE;
}

static gboolean test_layout_clear (Layout *layout, gpointer data)
{
	Test_Layout *test_layout;

	printf("call %s\n",__FUNCTION__);

	test_layout=layout->private;

	g_object_unref(test_layout->bg);

	g_free(test_layout);
}

gboolean test_layout_press(Layout * layout, GdkEventKey *event) {
	printf("start func %s\n" ,__FUNCTION__);
	Test_Layout *test_layout = layout->private;

	if(event->keyval==GDK_Up){
		printf("value: %f\n", gtk_adjustment_get_value(test_layout->vadjustment));
		//g_object_get(G_OBJECT(test_layout->vadjustment), "value", 200.0);
		gtk_adjustment_set_value(test_layout->vadjustment, 1080.0);
		return TRUE;
	}else if(event->keyval==GDK_Down){
		printf("value: %f\n", gtk_adjustment_get_value(test_layout->vadjustment));
		return TRUE;
	}

	return FALSE;
}

Layout *test_layout_new(GooCanvasItem *parent, gpointer sms){
	Layout *layout=layout_new(parent, LAYOUT_TYPE_WIN, LAYOUT_WIN_TEST, TEST_LAYOUT_NAME, sms);
	layout_set_func(layout,"init", test_layout_init);
	layout_set_func(layout,"clear", test_layout_clear);
	layout_set_func(layout,"key-press", test_layout_press);
	return layout;
}
